package com.rich.dmr.widget;

import android.annotation.SuppressLint;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;

public class MainActivity extends AppCompatActivity {
    public static final String ACTION_SHOW_DMR = "com.android.dmr.action.SHOW_CLOCK";
    private List<Integer> integerList = new CopyOnWriteArrayList<>();
    private Set<Integer> integerSet = new HashSet<>();
    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler(){
        @Override
        public synchronized void handleMessage(Message msg) {
            super.handleMessage(msg);
            if(msg.what == 0){
                mHandler.removeMessages(0);
                int bluetoothState = msg.arg1;
                Handler handler = (Handler)msg.obj;

            }
            Log.d("rich","");
            mHandler.obtainMessage(0,1,0).sendToTarget();
            mHandler.obtainMessage(1,mHandler).sendToTarget();
            integerSet.add(1);
            int size = integerList.size();

           // integerList.subList()
            mHandler.sendEmptyMessageDelayed(2,0);

        }
    };

    public <T> List<List<T>> averageAssign(List<T> source, int n) {
        List<List<T>> result = new ArrayList<List<T>>();
        int remainder = source.size() % n;  //(先计算出余数)
        int number = source.size() / n;  //然后是商
        int offset = 0;//偏移量
        for (int i = 0; i < n; i++) {
            List<T> value = null;
            if (remainder > 0) {
                value = source.subList(i * number + offset, (i + 1) * number + offset + 1);
                remainder--;
                offset++;
            } else {
                value = source.subList(i * number + offset, (i + 1) * number + offset);
            }
            result.add(value);
        }
        return result;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //int mode = Settings.System.getInt(getContentResolver(),"dmr_mode_key",0);
        //Log.d("rich----","mode="+mode);
    }
}
